List Less Than Ten列出少於十 << 
Previous Next >> Discussion討論區-3
Exercise 3 and Solution練習3和解決方案
Take a list, say for example this one:
  a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
and write a program that prints out all the elements of the list that are less than 5.
Extras:
- Instead of printing the elements one by one, make a new list that has all the elements less than 5 from this list in it and print out this new list.
- Write this in one line of Python.
- Ask the user for a number and return a list that contains only elements from the original list athat are smaller than that number given by the user.
拿一個清單,例如說一個:
  a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
並編寫一個程序,打印出列表中小於5的所有元素。
附加功能:
- 而不是一個一個地打印元素,而是創建一個新列表,其中該列表中的所有元素少於5個,然後打印出該新列表。
- 用一行Python編寫。
- 向用戶詢問一個數字,然後返回一個列表,該列表僅包含原始列表a中小於用戶給定數字的元素。
List Less Than Ten列出少於十 << 
Previous Next >> Discussion討論區-3